package com.shujia.spark.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo11MapValues {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("reduceByKey")

    val sc = new SparkContext(conf)

    val idAndAgeRDD: RDD[(String, Int)] = sc.parallelize(
      List(
        ("001", 23),
        ("002", 24),
        ("003", 25),
        ("005", 26)
      ))
    /**
     * mapValues: 用于处理value,key不变
     */

    val mapValuesRDD: RDD[(String, Int)] = idAndAgeRDD.mapValues((age: Int) => age + 1)

    mapValuesRDD.foreach(println)

  }

}
